package com.scalar.chiptrack.operations.discrepancyLotsNotifications.actions;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.scalar.chiptrack.ChipTrackExtendedAction;
import com.scalar.chiptrack.commons.SessionKeys;
import com.scalar.chiptrack.operations.discrepancyLotsNotifications.actionCommands.DiscripancyLotsNotificationsActionCommandFactory;

/**
 * Created by IntelliJ IDEA.
 * User: Murali Krishna Yengala
 * Date: Sep 12, 2005
 * Time: 3:06:15 PM
 * To change this template use File | Settings | File Templates.
 */
public class DiscrepancyLotsNotificationsAction extends ChipTrackExtendedAction {

    public ActionForward executeRequest( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
    {
        HashMap errors              = ( HashMap ) request.getAttribute( ERROR_MESSAGES );
        HashMap info                = ( HashMap ) request.getAttribute( INFO_MESSAGES );
        String action = request.getParameter("action");
        ActionForward actionForward = mapping.findForward( "loadLots" );


        if( action != null )
        {
            try
                {
                    ChipTrackExtendedAction discripancyLotsNotificationscommand = DiscripancyLotsNotificationsActionCommandFactory.getActionCommand( action );

                    if( discripancyLotsNotificationscommand == null )
                    {
                        errors.put( "Invalid request", null );
                    }
                    else
                    {
                        actionForward = discripancyLotsNotificationscommand.executeRequest( mapping, form, request, response );
                    }
                }
                catch( Exception e )
                {
                    errors.put( "Exception while processing Request", null );
                }
        }
        request.setAttribute (SessionKeys.INFO_MESSAGES, info);
        request.setAttribute (SessionKeys.ERROR_MESSAGES, errors);
        return actionForward;
    }
}
